[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.1 GDB Hints

Since debugging an AVR program with gdb requires gdb to connect to a remote target (either simulavr or some other debugging tool, such as avarice), a series of commands must be issued every time gdb is started. The easiest way around this is to put the commands into a ‘`.gdbinit`’ file in the project directory. The following example is from a ‘`.gdbinit`’ which I use for many projects.

    ## Print out structures in a sane way

    echo (gdb) set print pretty
    set print pretty

    ## Use this for debugging the remote protocol. (Don't use unless
    ## debugging simulavr or avr-gdb)

    #echo (gdb) set debug remote 1\n
    #set debug remote 1

    ## If you don't want specify the program to debug when invoking gdb,
    ## you can tell gdb to read it in here. The file should be an elf file
    ## compiled with debugging information (-g for C files and -gstabs for
    ## asm files).

    #echo (gdb) file myprog.elf\n
    #file myprog.elf

    ## Connect to the remote target via a TCP socket on host:port.

    echo (gdb) target remote localhost:1212\n
    target remote localhost:1212

    ## If you are using simulavr as the remote target, this will upload
    ## the program into flash memory for you.

    echo (gdb) load\n
    load

    ## Set a break point at the beginning of main().

    echo (gdb) break main\n
    break main

    ## Run the program up to the first break point.  Gdb's `run` command
    ## does not work when using a remote target, must use continue.

    echo (gdb) continue\n
    continue

As you can see, I `echo` every command so I can see what gdb has done when it runs the commands in the ‘`.gdbinit`’ file.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated by eweddington on November, 7 2008 using texi2html 1.78.